import { _decorator, Component, Node,Vec3 } from 'cc';
import { data } from '../data';
import { G } from '../G';
const { ccclass, property } = _decorator;

@ccclass('pipeMove')
export class pipeMove extends Component {

    private pipeWorldVec3 = new Vec3()
    private scoreStatus : boolean = false

    start() {
        this.pipeWorldVec3 = this.node.getWorldPosition()
    }

    update(deltaTime: number) {
        // 柱子移动
        if (data.gameStatus == 1) {
            this.pipeWorldVec3.x -= data.pipeV
            this.node.setWorldPosition(this.pipeWorldVec3.x, this.pipeWorldVec3.y, 0)
            // 加分~ 
            if (!this.scoreStatus && data.playerWouldVec.x > this.pipeWorldVec3.x + 40) {
                console.log('加分!');
                this.scoreStatus = true
                data.score += 1
                if (data.score != 0 && data.score % 10 == 0) {
                    G.gameRoot.addScoreBgmPlay()
                }
            }
            // 销毁柱子节点
            if (this.pipeWorldVec3.x < -40) {
                this.node.destroy()
            }
        }
    }

}


